home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Abalone 1.4.2 / src / StringLib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-21  |  952 b   |  87 lines  |  [TEXT/KAHL]

  1. #define STRINGLIB_C
  2. #include "StringLib.h"
  3.  
  4.  
  5. #if defined(__MWERKS__)
  6. #pragma segment __%Main
  7. #else
  8. #pragma segment Main
  9. #endif
  10.  
  11.  
  12. #define BASE 10
  13.  
  14.  
  15. void
  16. appendi2cstr (char *cstr, short i)
  17. {
  18.     i2cstr(cstr + strlen(cstr), i);
  19. }
  20.  
  21.  
  22.  
  23. short
  24. appendi2pstr (char *pstr, short i)
  25. {
  26.     short    j = 0;
  27.     if (i >= BASE) j = appendi2pstr (pstr, i / BASE);
  28.     pstr[++*pstr] = "0123456789ABCDEF"[i - j];
  29.     return (BASE * i);
  30. }
  31.  
  32.  
  33.  
  34. short
  35. i2cstr (char *cstr, short i)
  36. {
  37.     short    j;
  38.  
  39.     cstr[1] = j = 0;
  40.     if (i >= BASE)
  41.         j = i2cstr (cstr + 1, i / BASE);
  42.     *cstr = "0123456789ABCDEF"[i - j];
  43.     return (BASE * i);
  44. }
  45.  
  46.  
  47.  
  48. void
  49. i2pstr (char *pstr, short i)
  50. {
  51.     *pstr = 0;
  52.     appendi2pstr (pstr, i);
  53. }
  54.  
  55.  
  56.  
  57. void
  58. pstrcat (char *d, char *s)
  59. {
  60.     short    i;
  61.  
  62.     for (i = 0; i < s[0];)
  63.         d[++d[0]] = s[++i];
  64. }
  65.  
  66.  
  67.  
  68. void
  69. pstrcpy (char *d, char *s)
  70. {
  71.     short    i = *s;
  72.     do {
  73.         d[i] = s[i];
  74.     } while (i--);
  75. }
  76.  
  77.  
  78.  
  79. void
  80. pstrncpy (char *d, char *s, short n)
  81. {
  82.     short    i = *s;
  83.     do {
  84.         d[i] = s[i];
  85.     } while (i-- && n--);
  86. }
  87.